package com.wzdigit.wms.wms.service.core;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wzdigit.wms.basic.domain.inventory.Goods;
import com.wzdigit.wms.basic.domain.inventory.GoodsHis;
import com.wzdigit.wms.basic.mapper.core.inventory.GoodsHisMapper;
import net.dreamlu.mica.core.utils.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class GoodsHisService {

    @Autowired
    private GoodsHisMapper goodsHisMapper;


    public Goods selectGoodsByGoodsId(Integer goodsId) {
    	GoodsHis goodsHis = selectGoodsHisByGoodsId(goodsId);
    	Goods goods = new Goods();
    	BeanUtil.copyNonNull(goodsHis, goods);
        return goods;
    }
    
    public GoodsHis selectGoodsHisByGoodsId(Integer goodsId) {
        QueryWrapper<GoodsHis> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("GOODS_ID", goodsId);
        GoodsHis goodsHis = goodsHisMapper.selectOne(queryWrapper);
        return goodsHis;
    }

    /**
     * 通过 sn列表 获取货品详细信息
     *
     * @param listSn
     * @return
     */
    public List<Goods> selectListByListSn(List<String> listSn) {
        if (listSn != null && listSn.size() > 0) {
            QueryWrapper<GoodsHis> queryWrapper = new QueryWrapper<>();
            queryWrapper.in("GOODS_SN", listSn);
            List<GoodsHis> items = this.goodsHisMapper.selectList(queryWrapper);
            List<Goods> goodsList = new ArrayList<>();
            for (GoodsHis his : items){
                Goods goods = new Goods() ;
                BeanUtil.copyNonNull(his,goods);
                goodsList.add(goods);
            }
            return goodsList;
        }
        return new ArrayList<Goods>(0);
    }
}
